﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class morning_addGdzgTop : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
  
    }

    protected void btnSave_Click(object sender, EventArgs e)
    {
        TemporaryModel.TemporaryEntities dal = DAL.DBManager.GetTempEmtity();

        TemporaryModel.StockBusinessTop sbt = new TemporaryModel.StockBusinessTop();
        try
        {
            

            sbt.userName = txtUserName.Text;
            sbt.ydayTop = int.Parse(txtyDayTop.Text);

            sbt.dayrate = GetNum(txtDayRate.Text);
            sbt.totalrate = GetNum(txtTotalRate.Text);
            sbt.stockPositions = GetNum(txtStockPositions.Text);
            if (txtdProfitRate.Text != null && txtdProfitRate.Text!="")
                sbt.dProfitRate = GetNum(txtdProfitRate.Text);

            sbt.amount = decimal.Parse(txtAmount.Text);
         
            sbt.totalAmount = decimal.Parse(txtTotalAmount.Text);
            sbt.wtDate =DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd"));
            try
            {
                dal.AddToStockBusinessTop(sbt);
                dal.SaveChanges();
                ClientScript.RegisterStartupScript(GetType(), "save", "alert('添加成功')", true);
                ClearTxt();
            }
            catch
            {
                ClientScript.RegisterStartupScript(GetType(), "save", "alert('添加失败')", true);
            }
        }
        catch
        {
            ClientScript.RegisterStartupScript(GetType(), "save", "alert('录入数据格式有误！请检查数据格式是否正确')", true);
        }

  
    }

    public void ClearTxt()
    {
        txtUserName.Text = "";
        txtyDayTop.Text = "";
        txtDayRate.Text = "";
        txtTotalRate.Text = "";
        txtAmount.Text = "";
        txtStockPositions.Text = "";
        txtdProfitRate.Text = "";
        txtTotalAmount.Text = "";
    }

    public decimal GetNum(string str)
    {
        if (str.Contains("%"))
        {
            str = str.Replace("%", "");
            decimal dl = decimal.Parse(str) / 100;
            return dl;
        }
        else
        {
            return decimal.Parse(str);
        }
    }
}